package cn.com.ninng;

import java.util.ArrayList;
import java.util.List;

/**
 * 判断一个数是否为回文数
 *
 * @author liulekang
 * @createdate 2021/7/28
 */
public class Problem9 {

    public static void main(String[] args) {
        System.out.println(isPalindrome(123));
    }


    public static boolean isPalindrome(int x) {
        if (x < 0) {
            return false;
        }
        if (x < 10) {
            return true;
        }
        if (x % 10 == 0) {
            return false;
        }
        List<Integer> nums = new ArrayList<>();
        //解析数字的每一位
        int num = x;
        while (num!=0){
            int e = num % 10;
            nums.add(e);
            num = num/10;
        }
        //反转数字
        int x2 = 0;
        //每一位的权值
        int power = 1;
        for (int i = nums.size() -1 ; i >= 0; i--) {
            x2 = nums.get(i) * power;
            power *= 10;
        }
        return x == x2;
    }



}
